const labelService = require('../service/label.service');
const momentService = require('../service/moment.service');

class labelController {
    async create (ctx, next) {
       const {name} = ctx.request.body;
    //    console.log(name);
       const result = await labelService.create(name);
       ctx.body = result;
    }

    async getLabels (ctx, next) {
       const { offset, size} = ctx.query;
       const result = await labelService.getLabels(offset, size);
       ctx.body = result;
    }

    async update (ctx, next) {
       const {labels} = ctx;
       const {momentId} = ctx.params;
       console.log(labels);
      //  console.log(momentId);
      //  console.log(labels);
      const result = await labelService.deleteLabels(momentId);
      if (!result) {
         ctx.body = '删除标签数据失败';
         return;
      }
     for(let label of labels) {
      const result = await momentService.addLabel(momentId, label.id);
      ctx.body = '动态修改成功';
     }
    }
} 

module.exports = new labelController();